package com.cameron.oos.controller;

import com.cameron.oos.service.OssService;
import com.cameron.utils.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author cameron
 */
@RestController
@RequestMapping("/file-service/oos-file")
@CrossOrigin
public class OssController {

    @Resource
    private OssService ossService;

    @PostMapping("upload")
    public Result upload(MultipartFile file){
        String url = ossService.uploadAvatar(file);
        return StringUtils.isNotEmpty(url) ? Result.ok().data("url",url) : Result.error();
    }
}
